package com.cbwl.eoas.cms.web.controller.sysconfig;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cbwl.eoas.cms.api.sysconfig.IDictDetailService;
import com.cbwl.eoas.cms.api.sysconfig.IDictTypeService;
import com.cbwl.eoas.cms.api.sysconfig.ISysEmployeeService;
import com.cbwl.eoas.cms.model.sysconfig.DictDetailDTO;
import com.cbwl.eoas.cms.model.sysconfig.SysEmployeeDTO;
import com.cbwl.eoas.common.framework.session.SessionManager;
import com.cbwl.eoas.common.framework.vo.PageRequest;
import com.cbwl.eoas.common.util.constain.DicTypeConstant;
import com.cbwl.eoas.common.web.Result;
import com.github.pagehelper.PageInfo;



/**
 * 
 * <p>[描述信息：职员管理Controller]</p>
 *
 * @author 虞云波 - yuyunbo@3856.cc
 * @version 1.0 Created on 2017年10月12日 下午13:29:23
 */
@Controller
@RequestMapping("/sysemployee")
public class SysEmployeeController {
	
	//业务层注解
	@Autowired
	private ISysEmployeeService sysEmployeeService;
	
	//业务层注解
	@Autowired
	private IDictDetailService dictDetailService;
	
	
	
	private static Logger logger = LoggerFactory.getLogger(SysEmployeeController.class);
	
	/**
	 * <p>初始化界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initSysEmployee")
	public String initSysEmployeePage() {
		return "initSysEmployee";
	}


	/**
	 * <p>初始化新增修改界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initAddUpdateSysEmployeePage")
	public String initAddUpdateSysEmployeePage(HttpServletRequest request,SysEmployeeDTO bean) {
		request.setAttribute("bean", bean);
		

		DictDetailDTO detailBean = new DictDetailDTO();
		detailBean.setDictTypeNo(DicTypeConstant.emp_status);
		request.setAttribute("detailBean", dictDetailService.queryObjectList(detailBean));
		
		return "initAddUpdateSysEmployeePage";
	}
	

	/**
	 * <p>查询（分页）</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/querySysEmployeePage")
	@ResponseBody
	public Object querySysEmployeePage(SysEmployeeDTO bean,PageRequest pageRequest) {
		
		Result result = new Result(Result.Status.OK, "查询成功", "200");
		// 分页查询用户信息
		PageInfo<?> empPageInfo =  sysEmployeeService.queryPageList(bean,pageRequest);
		result.setData(empPageInfo);
		return result;
	}

	/**
	 * 
	 * <p>通过id查询主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/getSysEmployeeById")
	@ResponseBody
	public Object getSysEmployeeById(SysEmployeeDTO bean) {
		return sysEmployeeService.getObjectById(bean);
	}

	/**
	 * 
	 * <p>保存主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/saveSysEmployee")
	@ResponseBody
	public Object saveSysEmployee(SysEmployeeDTO bean) throws Exception {


		bean.setGmtCreate(new Date());
		bean.setCreater(SessionManager.getCurrentUser().getId());
		logger.info("{}保存了职员信息,职员名称{}", SessionManager.getCurrentUser().getEmpName(),bean.getEmpName());
		return sysEmployeeService.saveObject(bean);
	}

	/**
	 * 
	 * <p>更新主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/updateSysEmployee")
	@ResponseBody
	public Object updateSysEmployee(SysEmployeeDTO bean) throws Exception {		
		bean.setGmtModified(new Date());
		bean.setModifier(SessionManager.getCurrentUser().getId());
		logger.info("{}修改了职员信息,职员名称{}", SessionManager.getCurrentUser().getEmpName(),bean.getEmpName());
		return sysEmployeeService.updateObject(bean);
	}

	/**
	 * 
	 * <p>删除主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc 
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 * @throws Exception 
	 */
	@RequestMapping("/deleteSysEmployee")
	@ResponseBody
	public Object deleteSysEmployee(SysEmployeeDTO bean) throws Exception {
		logger.info("{}删除了职员信息,职员名称{}", SessionManager.getCurrentUser().getEmpName(),bean.getEmpName());
		return sysEmployeeService.deleteObject(bean);
	}
}
